if lib and not lib.getParamEx then


function lib:getParamEx(instrument, db_name)
	if type(instrument) == "string" then
		instrument = self:GetInstrument(instrument)
	end
	
	if type(instrument) == "table" then
		if not self.ParamRequests then self.ParamRequests = {} end
		if not self.ParamRequests[instrument.code] and ParamRequest(instrument.class_code, instrument.code, db_name) then
			self.ParamRequests[instrument.code] = true
		end
		
		local p = getParamEx(instrument.class_code, instrument.code, db_name)
		
		if p.result == "1" then
			return tonumber(p.param_value)
		end
	end
	return 0
end


function lib:GetLotSize(instrument)
	if type(instrument) == "string" then
		instrument = self:GetInstrument(instrument)
	end
	
	if type(instrument) == "table" then
		if instrument.class_code == "SPBFUT" then
			return self:getParamEx(instrument, "stepprice") / instrument.min_price_step
		end
		return instrument.lot_size
	end
end


function lib:CheckStop(instrument, is_long, price)
	local last = self:getParamEx(instrument, "last")
	if last then
		if is_long then
			return price < last
		else
			return price > last
		end
	end
end


function lib:CanShort(instrument)
	if type(instrument) == "string" then
		instrument = self:GetInstrument(instrument)
	end
	
	if type(instrument) == "table" then
		if instrument.is_short_allowed == nil then
			local info = getBuySellInfoEx(
				self:GetFirmID(),
				self:GetClientCode(),
				instrument.class_code,
				instrument.code,
				0
			)
			if info then
				instrument.is_short_allowed = info.is_short_allowed == "1"
			else
				return true
			end
		end
		
		return instrument.is_short_allowed, instrument.is_short_allowed
	end
	
	return true
end


function lib:GetInstrumentTradeTime(instrument)
	if not self.instrument_trade_time then self.instrument_trade_time = {} end
	local td = self:getTradeDate()
	local tf = self:FormatDate(td)
	local tt = self.instrument_trade_time[instrument.code or instrument]
	if tt and tt.trade_date == tf then
		return tt.first, tt.last
	else
		local first, last, candle
		local ds = self:CreateDataSource(instrument)
		if ds then
			for i = 1, 1440 do
				candle = self:GetLastCandle(ds, i)
				if candle and candle.volume > 0 then
					tt = candle.datetime.hour * 60 + candle.datetime.min
					if not first or first > tt then first = tt end
					if not last or last < tt then last = tt end
				end
			end
			if first then
				first = self:clone({
					hour = int(first / 60),
					min = first % 60,
					sec = 0,
					ms = 0,
					mcs = 0
				}, td)
				last = self:clone({
					hour = int(last / 60),
					min = last % 60,
					sec = 59,
					ms = 999,
					mcs = 999
				}, td)
				self.instrument_trade_time[instrument.code or instrument] = {
					trade_date = tf,
					first = first,
					last = last
				}
			end
		end
		return first, last
	end
end


end -- of file
